<?php
function ok_page($ok_title,$ok_desc,$ok_text,$link,$print_elem){
$printquery = "";
	if(isset($GLOBALS['printtype'])){
	if($GLOBALS['printtype'] == "bill"){
		echo $printquery = "bill_id=" . $GLOBALS['bill_id'];
	} 
	else if($GLOBALS['printtype'] == "reservation"){
		echo $printquery = "reserv_gid=" . $GLOBALS['reserv_gid'];
	}
}
?>

<?php
function ok_print(){
   ?>     
   <p class="from-command rounded_5px"><img src="./img/printer.png" alt="print">
<span class="form-footer"><input class="button print" id="button_print" name="print" value="print" type="submit"></span>
<span style="padding:5px 0 0 5px;">กดปุ่มเพื่อทำการพิมพ์ข้อมูลผ่านเครื่องพิมพ์</span></p>
<div id="print-elem" style="display:none;">dasdasds</div>    
<?php } ?>        
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html class=" gecko ff3 mac js" xmlns="http://www.w3.org/1999/xhtml"><head>


  		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  		<title>สำเร็จ !</title>
  		<link href="./css/do.css" media="screen" rel="stylesheet" type="text/css">
  		<link media="screen" rel="stylesheet" href="css/main.css" type="text/css">
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="./js/jquery-ui.js"></script>
  <script src="./js/jquery.jqprint.0.3.js" type="text/javascript"></script>
  <script type="text/javascript">
  
  function submitCalCost(){
  	var reserv_gid = $("input#reserv_gid").val();
  	var cost = $("input#overall_price_discounted").val();
  	var roomList = $("#roomList").val();
  	var discList = "";
  	if(typeof roomList != 'undefined'){
  	  	var roomListArray = roomList.split(",");
  	  	for(var i = 0; i < roomListArray.length; i++){
  	  		discList += ","+$("#discount_"+jQuery.trim(roomListArray[i])).val();
  	  	}
  	 	discList = discList.substr(1,discList.length);
  	}
  	var respondsContent = $.ajax({
      url: "doCalCost.php",
      global: false,
      type: "POST",
      data: ({reserv_gid : reserv_gid,cost : cost, roomList : roomList, discList : discList}),
      dataType: "html",
      async:false}).responseText;
/*   	alert(respondsContent); */
	
  	$("#ok_form").submit();
  }
  
  function calByRoom(id){
  		var price_total = 0;
  		var overall_roomprice = $('#'+id).text();
  		var discount_percent = $('#discount_'+id).val();
  		var discount = (overall_roomprice*discount_percent)/100;
  		var overall_roomprice_discount = overall_roomprice - discount;
  		$("#overall_roomprice_"+id).html(overall_roomprice_discount);
  		
  		$('div.overall_roomprice').each(function(index) {
    		var price = $(this).text() * 1;
    		console.log(price);
    		price_total += price;
    	});
    	var extra_bed = $("input#all_extrabed").val();
    	price_total = price_total+(extra_bed*400);
    	$("h3#overall_price").html(price_total);
		$("input#overall_price_discounted").val(price_total);
  }
              $(function() {
              var discount_percent;
               var discount;
               var price_discounted;
                  $("#button_print").click( function() {
window.open('print.php?reserv_gid=40', 'printpage', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=480')
                      return false;
                  });
                  $("#cal_button").click( function() {
          			var price = $("input#overall_price").val();
				    discount_percent = $("input#discount").val();
				    discount = (price*discount_percent)/100;
				    price_discounted = price - discount;
				    $("h3#overall_price").html(price_discounted);
				    $("input#overall_price_discounted").val(price_discounted);
                      return false;
                  });
			   /*
$("input#cash").keyup(function() 
			    {
				    //var discount = $("input#discount").val();
				    var price = $("input#overall_price").val();
				    if(discount_percent == null){
					    discount = 0;
					    price_discounted = price - discount;
				    }
				    var change = $("input#cash").val() - price_discounted;
				    //price = $("input#cash").val()-$("input#overall_price").val();
					$("span#change").html(change);
					$("input#change").val(change);
					$("input#overall_price_discounted").val(price_discounted);
			    });
*/
			   $("input#discount").keyup(function() 
				{
				    var price = $("input#overall_price").val();
				    discount_percent = $("input#discount").val();
				    discount = (price*discount_percent)/100;
				    price_discounted = price - discount;
				    $("h3#overall_price").html(price_discounted);
				    $("input#overall_price_discounted").val(price_discounted);
					//price = (price*discount)/100;
					//$("span#change").html(price);
					//$("input#change").val(price);
					//$("span#change").html(price);
					//$("input#change").val(price);
				});
              });

          </script>
  </head><body id="panel" class="setup"><?//echo //$printtype;?>
      <ul class="panel_list">
        <li class="panel_item active open">
          <div class="panel_header">
            <h1>สำเร็จ !</h1>
            </div>

          <div class="panel_content">
        	 <div class="tab-content rounded_bottom_5px selected" id="tab_1-content">
  <form action="<?=$link?>" class="form" id="ok_form" method="post">
    <div class="ok">

    </div>
    <fieldset class="getting-started">
            <h3><?=$ok_title?></h3>
            <p><?=$ok_desc?></p>
            <p style="text-align: center;"><img src="./img/ok.png"></p>
      <p><?=$ok_text?></p>
                <?
  		if($print_elem!=""){
/*   		        ok_print(); */
  		}?>
  		
		<div class="form-footer"><span><input class="button continue" id="button_submit" name="commit" value="Continue" type="button" onclick="submitCalCost();"></span></div>
    </fieldset>
  </form>
  </div>
        	</div>
        </li>
      </ul>

  	</body></html>
<?php } ?>

